<?php
use common\components\helpers\Fun;
use common\components\extenders\MenuManage;
?>
<div style="margin: 10px">
    <a href=<?= Fun::url(['customer/index']) ?>><font class="button">返回列表</font></a>&nbsp;
    <a><?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer','card',false,['rel'=>'dialog-charge-iframe','class' => 'button','data'=>['id'=>\Yii::$app->request->get('id')]]);?></a>
    <a><?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer','change',false,['rel'=>'dialog-charge-iframe','class' => 'button','data'=>['id'=>\Yii::$app->request->get('id')]]);?></a>
    <a><?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer','charge',false,['rel'=>'dialog-charge-iframe','class' => 'button','data'=>['id'=>\Yii::$app->request->get('id'),'orders_id'=>\Yii::$app->request->get('orders_id')]]);?></a>
    <a><?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer','consume',true,['class' => 'button','data'=>['id'=>\Yii::$app->request->get('id')]]);?></a>
    <a><?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer','order',true,['class' => 'button','data'=>['id'=>\Yii::$app->request->get('id')]]);?></a>
    <a><?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer','bind',false,['rel'=>'dialog-charge-iframe','class' => 'button','data'=>['id'=>\Yii::$app->request->get('id')]]);?></a>
    <?php if($orders_id):?>
    <a href=<?= Fun::url(['orders/details','id'=>$orders_id]) ?>><font class="button">返回支付订单</font></a>
    <?php endif;?>
</div>

<fieldset>
    <legend id="customer_info" data-student="<?=count($student)?>" data-customer_id="<?=$model->id?>" data-url="<?=Fun::url(['customer/chose']);?>" data-href="<?=Fun::url(['customer/details','id'=>$model->id])?>"><h3>会员基本信息</h3></legend>
    <table class="table-form" style="width: 80%; margin:10px auto;">
        <tr>
            <td>姓名：</td>
            <td><?= \yii\helpers\Html::encode($model->name); ?></td>
            <td>性别：</td>
            <td><?php
                switch ($model->sex) {
                    case 'Male':
                        echo '男';
                        break;
                    case 'Female':
                        echo '女';
                        break;
                } ?></td>
        </tr>
        <tr>
            <td>年龄：</td>
            <td><?= \yii\helpers\Html::encode($model->age); ?></td>
            <td>电话：</td>
            <td><?= \yii\helpers\Html::encode($model->mobile); ?></td>
        </tr>
        <tr>
            <td>账户：</td>
            <td id="accountrecord"><?= \yii\helpers\Html::encode($model->account); ?></td>
            <td>积分：</td>
            <td><?= \yii\helpers\Html::encode($model->integral); ?></td>
        </tr>
    </table>
</fieldset>
<div>
    <?php if(count($student)>0){?>
    <fieldset>
        <legend><h3>学员基本信息</h3></legend>
        <div>
        <?php foreach($student as $k=>$v){?>
            <div
                style="border: solid 1px #95b8e7 ;margin: 15px; width: 350px;height:100px; background-color: #e0ecff   ;float: left;border-radius:5px ;padding:5px;box-shadow: 1px 1px 1px #000  ;">
                <div style="float: right;width:80px;padding: 5px">
                <?php
                if(empty($v['IDcard'])){?>
                    <a><?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer','addidcard',false,['rel'=>'dialog-add-iframe','class' => 'button','style' => "float:right;",'data'=>['id'=>$v['id']]])?></a>
                <?php }?>
                </div>
                <p>学员名称：<?=$v['name'] ?></p>
                <p>昵称：<?=$v['nickname'] ?></p>
                <p>年龄：<?=$v['age']?>岁</p>
                <p>性别：<?php switch ($v['sex']) {
                        case '0':
                            echo '女';
                            break;
                        case '1':
                            echo '男';
                            break;
                    }?></p>
                <p>创建时间：<?=\Yii::$app->formatter->asDatetime($v['created_at'])?></p>
            </div>
            <?php }?>
            </div>
        </fieldset>
    <?php }?>

    <?php if($category_count>0){?>
    <fieldset>
        <legend><h3>预约类别信息</h3></legend>
        <div>
            <div>
                <?php foreach($ordercategory_history as $k => $v){?>
                    <div style="border: solid 1px #95b8e7 ;margin: 15px; width: 350px;height:75px; background-color: #e0ecff   ;float: left;border-radius:5px ;padding:5px;box-shadow: 1px 1px 1px #000  ;">
                        <div style="float: right;width:80px;padding: 5px">
                           <?php if($v->is_deposit==0){?>
                            <a><?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer','deposit',false,['rel'=>'','class'=>'deposit button','data'=>['id'=>$v->id],'data-idcard'=>isset($v->student)?$v->student->IDcard:'','data-account'=>$model->account,'data-deposit'=>isset($v->ordersales->order)?$v->ordersales->order->actual_pay:-1])?><?php }
                           else {?>
                             <?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer','addcourse',false,['rel'=>'dialog-chose','class'=>'selection button','id' => "chose$k",'data'=>['category_id'=>$v->ordersales->category_id],'ordercourse_history_id'=>$v->id])?>
                           <?php }?>
                        </div>
                        <p>类别名称：<?=$v->ordersales->category_name?></p>
                        <?php if($v->bind_id!=null){?>
                        <p>绑定学员：<?=isset($v->student)?$v->student->name:''?></p><?php } ?>
                        <p>上课时间：<?= Fun::getClassTime(isset($v->ordersales->classroomAttr)?$v->ordersales->classroomAttr->start_time:'',isset($v->ordersales->classroomAttr)?$v->ordersales->classroomAttr->end_time:'',isset($v->ordersales->classroomAttr)?$v->ordersales->classroomAttr->classday:'');?></p>
                        <p>预约时间：<?= \Yii::$app->formatter->asDatetime($v->created_at) ?></p>
                    </div>
                <?php } ?>
            </div>
        </div>
    </fieldset>
    <?php }?>

    <?php if($course_count>0){?>
    <fieldset>
        <legend><h3>预约课程信息</h3></legend>
        <div>
            <div>
                <?php foreach($ordercourse_history as $k => $v){if(isset($v->ordersales)&& $v->ordersales->can_back_number>0){?>
                    <div style="border: solid 1px #95b8e7 ;margin: 15px; width: 350px;height:110px; background-color: #e0ecff   ;float: left;border-radius:5px ;padding:5px;box-shadow: 1px 1px 1px #000">
                        <div style="float: right;width:80px;padding: 5px">
							
                            <?php if($v->is_deposit==0){?>
                                 <a><?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer','deposit',false,['rel'=>'','class'=>'deposit button','data'=>['id'=>$v->id],'data-idcard'=>isset($v->student)?$v->student->IDcard:'','data-account'=>$model->account,'data-deposit'=>isset($v->ordersales->order)?$v->ordersales->order->actual_pay:-1])?>
                            <?php }
                            else {if($v->is_transform==0){?>
                                <a><?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer','transform',true,['rel'=>'','style' => "float:right;",'class' => 'button','data'=>['id'=>$v->id]]);?></a>	
							<?php }}?>
							<?php if(isset($v->ordersales->classStudent->classManage) && ($v->ordersales->classStudent->classManage->status == 1)):?>
                                    <a id="chose14" class="button" rel="dialog-add-iframe" style="float:right; margin-top: 5px" data-url="<?=Fun::url(['classmanage/sign','class_id'=>isset($v->ordersales->classStudent->class_manage_id)?$v->ordersales->classStudent->class_manage_id:0,'id'=>isset($v->student->id)? $v->student->id:0])?>" data-size="1100*400">课时</a>
                                <?php endif;?>
                                
                        </div>
                        <p>课程名称：<?= (isset($v->ordersales->course))?$v->ordersales->course->name:''?></p>

                        <p>教师名称：<?= (isset($v->ordersales->teacher))?$v->ordersales->teacher->name:'' ?></p>

                        <p>教室编码：<?= (isset($v->ordersales->classroom))?$v->ordersales->classroom->room_number:'' ?></p>

                        <p>预约时间：<?= \Yii::$app->formatter->asDatetime($v->created_at) ?></p>
                        <?php if($v->bind_id!=null){?>
                            <p>绑定学员：<?= isset($v->student)?$v->student->name:''?></p><?php } ?>
                        <p>已上课次/总课次：<?= count($v->studentcheck) ?>/<?=isset($v->ordersales)?$v->ordersales->class_count:''?></p>
                    </div>
                <?php }}?>
            </div>
        </div>
    </fieldset>
    <?php }?>

    <?php if(count($order)>0){?>
    <fieldset>
        <legend><h3>订单课程信息</h3></legend>
        <div>
            <?php foreach($order as $k => $v){ foreach ($v->orderSales as $key => $val) { if ($val->type == 0 && $val->can_back_number>0) {?>
                <div  style="border: solid 1px #95b8e7 ;margin: 15px; width: 350px;height:130px; background-color: #e0ecff   ;float: left;border-radius:5px ;padding:5px;box-shadow: 1px 1px 1px #000  ;">
                    <div style="float: right;width:80px;padding: 5px">
                    <?php if($val->student_id==null && $val->type==0 &&substr_count($v->order_number,'xf')){?>
                    <a><?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer','bound',false,['rel'=>'dialog-add-iframe','class' => 'button','style' => "float:right;",'data'=>['id'=>$val->id,'order_id'=>$v->id]])?></a><?php }else {?>
                    <a><?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('customer','renew',true,['rel'=>'','class' => 'renew_button button','style' => "float:right;",'data' => ['id'=>$val->id]])?></a><?php }?>
                    </div>
                    <div id="aaa">
                    <p>订单编号：<?= \yii\helpers\Html::encode($v->order_number);?></p>
                    <p>课程名称：<?= isset($val->course->name) ? \yii\helpers\Html::encode($val->course->name) : '' ?></p>
                    <p>教师名称：<?= isset($val->teacher->name) ? \yii\helpers\Html::encode($val->teacher->name) : '' ?></p>
                    <p>教室编码：<?= isset($val->classroom->room_number) ? \yii\helpers\Html::encode($val->classroom->room_number) : '' ?></p>
                    <?php if($val->student_id!=null){?>
                        <p>绑定学员：<?= isset($val->student)?$val->student->name:''?></p><?php } ?>
                    <p>创建时间：<?= \Yii::$app->formatter->asDatetime($v['created_at'])?></p>
                    <p>上课时间：<?=Fun::getClassTime($val->start_time,$val->end_time,$val->class_day);?></p>
                     </div>
                </div>
            <?php }}}?>
        </div>
    </fieldset>
    <?php }?>

</div>
<?php
$js = <<<JS
    //交定金
    $('.deposit').click(function () {

        var _this=$(this);
        var account=Number(_this.data('account'));
        var deposit=Number(_this.data('deposit'));
        var IDcard=(_this.data('idcard'));
        if(IDcard==undefined ||IDcard==''){
            alert("请先完善该学员的资料！");return false;
        }
        else if(deposit==-1){
            alert("定金金额确缺失，请先核实，确定定金金额！");return false;
        }
        else if(deposit>account){
                alert("账户金额不足，差额"+accAdd(deposit,-account)+"元,请先充值！");
                return false;
        }else{
            $.messager.confirm('确认', "确定交"+deposit+"元定金？", function (r) {
                if (r) {
                    var url = _this.attr('data-url');
                    $.post(url, {ajax: 'deposit',_csrf:yii.getCsrfToken()}, function (data) {
                        alert(data);
                        reloadData();
                    }, 'json');
                }
                else {
                    return false;
                }
            });
        }

    });
    //绑定
    $('.bind').click(function () {
        var count=Number($('#customer_info').data('student'));
        if(count==0){
            alert('请先添加绑定学员！');return false;
        }
    });
    //选课
    $(document).on('click', 'a[rel=dialog-chose]', function () {
        var ordercourse_history_id= $(this).attr('ordercourse_history_id');
            var dialog_size = $(this).data('size');
            var dialog_witdh = dialog_size.indexOf('*') > 0 ? dialog_size.split('*')[0] : 500;
            var dialog_height = dialog_size.indexOf('*') > 0 ? dialog_size.split('*')[1] : 500;
            window.top.$('#dialog-create', top.document).dialog({
                title: $(this).html(),
                width: dialog_witdh,
                height: dialog_height,
                resizable: true,
                closed: false,
                cache: false,
                content: '<iframe id="form-iframe" marginheight="0" marginwidth="0" frameborder="0" scrolling="yes" style="width:100%; height:100%;" src="' + $(this).data('url') + '">',
                modal: true,
                buttons:[{
                    text:'保存',
                    handler:function(){
                        var array = window.top.document.getElementById('form-iframe').contentWindow.checkbox_selected_value;
                        if(array.length>1){alert("只能选择1门,请重新选择！");return false;}
                        else {
                            var sales_id=array[0]['id'];
                            var url =$('#customer_info').data('url');
                            var href =$('#customer_info').data('href');
                            var customer_id =$('#customer_info').data('customer_id');
                            $.post(url, {ajax: 'chose',customer_id:customer_id,sales_id:sales_id,ordercourse_history_id:ordercourse_history_id,_csrf:yii.getCsrfToken()}, function (data) {
                                alert(data);
                                setTimeout(function () {
                                    window.location = href;
                                }, 1000);
                            }, 'json');
                            clearDialog();
                        }
                    }
                },{
                    text:'关闭',
                    handler:function(){
                        clearDialog();
                    }
                }]
            });
    });
    function reloadData() {
        document.location.reload();
    }
JS;
$this->registerJS($js);
?>